# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Maintainer: Jonathan Sieber <mail@strfry.org>
pkgname=toxcore
pkgver=0.2.18_git20230303
pkgrel=1
_cmpver=20
_gitrev=172f279dc0647a538b30e62c96bab8bb1b0c8960
pkgdesc="Tox communication project - Core Library"
url="https://tox.chat/"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	cmake
	libconfig-dev
	libsodium-dev
	libvpx-dev
	linux-headers
	opus-dev
	samurai
	"
subpackages="$pkgname-dev $pkgname-bash-completion"
source="$pkgname-$pkgver.tar.gz::https://github.com/TokTok/c-toxcore/archive/$_gitrev.tar.gz
	cmp-$_cmpver.tar.gz::https://github.com/camgunz/cmp/archive/refs/tags/v$_cmpver.tar.gz
	"
builddir="$srcdir/c-toxcore-$_gitrev"
# Toxcore's tests do require networking and are not working properly in Travis-CI
options="!check"


prepare() {
	mv ../cmp-$_cmpver/* third_party/cmp/
	default_prepare
}

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_INSTALL_LIBDIR=lib

	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	rm -f "$pkgdir"/usr/lib/*.a
}

sha512sums="
d3d9460fa788af5146c6a34f7c81330f5f3eeacfadd7c0fca9187c6634138ed8c5fef294e03d0e025cb9980e2957e29a4efeb66907d082abd14f46507f6bf3c4  toxcore-0.2.18_git20230303.tar.gz
f747cb9672592d8c06d08786152a0bfbd6ae4d759d7006805913781c502bf3796241ade636ce2cf9c049f68dd2899e2d5d7008815f29c1a91fc797590a26a9fd  cmp-20.tar.gz
"
